import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

class TodayPage extends StatelessWidget{
  TodayPage({this.title});
  final String title;
  @override
  Widget build(BuildContext context){
    return new ListView(
      padding: new EdgeInsets.only(top: 30.0, left: 14.0, right: 14.0),
      children: <Widget>[
        new ListItem(title: 'Today', date: new DateTime.now(),),
        new ListItem(title: '周五', date: new DateTime.now().subtract(new Duration(days: 1)),),

      ],
    );
  }


}

class ListItem extends StatelessWidget{
  ListItem({this.title, this.date});
  final String title;
  final DateTime date;
  @override
  Widget build(BuildContext context){
    return new Container(
      child: new Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          new HeadView(dateStr: _dateFormat(date), weektip: _weekdayStr(date),),
          new ContentCard(),
          new ContentCard(),

        ],
      ),
      margin: new EdgeInsets.only(bottom: 10.0),
    );
  }
  String _dateFormat(DateTime date){
    var formatter = new DateFormat('MM-dd');
    return formatter.format(date);
  }
  String _weekdayStr(DateTime date){
    if (_dateFormat(date) == _dateFormat(new DateTime.now())){
      return 'Today';
    }
    switch(date.weekday){
      case DateTime.SUNDAY:
        return '周日';
      case DateTime.MONDAY:
        return '周一';
      case DateTime.TUESDAY:
        return '周二';
      case DateTime.WEDNESDAY:
        return '周三';
      case DateTime.THURSDAY:
        return '周日';
      case DateTime.FRIDAY:
        return '周五';
      case DateTime.SATURDAY:
        return '周六';
      default:
        return '周$date.weekday';
    }
  }
}
class ContentCard extends StatelessWidget{
  @override
  Widget build(BuildContext context){
    //Theme.of(context)

    return new Container(
      margin: const EdgeInsets.only(top: 5.0),
      decoration: new BoxDecoration(
        borderRadius: new BorderRadius.all(new Radius.circular(70.0)),
      ),
      child: new GestureDetector(
        child: new Card(
          child: new Image.asset('images/p.jpg', height: 300.0, width: 250.0, fit: BoxFit.fill,),

        ),
        onTap: (){
          Navigator.of(context).pushNamed('/game');
        },
      ));
  }
}
class HeadView extends StatelessWidget{
  HeadView({this.dateStr, this.weektip});
  final String dateStr;
  final String weektip;
  @override
  Widget build(BuildContext context){
    TextTheme textTheme = Theme.of(context).textTheme;
    return new Row(
      mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        new Column(
          crossAxisAlignment: CrossAxisAlignment.start,

          children: <Widget>[
            new Text(dateStr, style: new TextStyle(color: Colors.grey[400], fontSize: 18.0),),
            new Text(weektip, style: new TextStyle(color: Colors.black, fontSize: 33.0),),
          ],
        )
      ],
    );
  }
}
TodayPage instancePage(String title){
  return new TodayPage(title: title);
}
